' Convert ounces to pounds PRINT "Enter number of ounces" INPUT OUNCES PRINT "Number of pounds:", OUNCES / 16 END
When an INPUT
statement asks for a number,
it will reject an unacceptable number and
ask that you type it again.
This can get confusing unless you look carefully
at what happens.
Say that the above program is run and that the
INPUT
statement has asked for a number.
The user has typed "rats" but has not yet hit
enter.
Enter number of ounces ? rats
"rats" is not acceptable when INPUT
expects a number.
When the user hits enter, the following will appear:
Enter number of ounces ? rats Redo from start ? _
The INPUT
statement did not accept "rats" and so writes
the prompt "Redo from start" and then writes the "?" as
usual.
Notice that the program is "stuck" on the INPUT
statement.
It won't do the PRINT
statement (or any other) again, so
you won't see the "Enter number of ounces" prompt again.
Now say that the user enters an acceptable value:
Enter number of ounces ? rats Redo from start ? 12 Number of pounds .75
Once the INPUT
statement gets an acceptable number,
it continues as usual by putting the number in the variable.
The rest of the program executes as usual.
An "acceptable number" means something you typed that looks like a number.
The number might be incorrect data.
The INPUT
statement does not know when it is given
incorrect data.
Here again is the program to convert ounces to pounds:
' Convert ounces to pounds PRINT "Enter number of ounces" INPUT OUNCES PRINT "Number of pounds:", OUNCES / 16 END
The user types the weight in ounces of a newborn baby boy expecting to get the weight in pounds.
Enter number of ounces ? 640
What will the program do?